import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @author xhw
 */

@AllArgsConstructor
@EqualsAndHashCode
@Getter
public class GroupKey implements Comparable<GroupKey>{
    //存储的是行列的数据，要实现排序
    private List<String> rowsKeys;
    private List<String> columnsKeys;

    @Override
    public int compareTo(@NotNull GroupKey o) {
        int result = compareToGroupKey(this.rowsKeys, o.rowsKeys);
        //如果行的数据相等，就比较列的数据
        if (result != 0) {
            return result;
        }
        return compareToGroupKey(this.columnsKeys, o.columnsKeys);
    }

    //重写一个比较方法,返回一个数字，大于返回1，小于返回-1，等于返回0
    private int compareToGroupKey(List<String> Keys, List<String> Okeys) {
        int minSize = Math.min(Keys.size(), Okeys.size());
        for (int i = 0; i < minSize; i++) {
            int result = Keys.get(i).compareTo(Okeys.get(i));
            if (result != 0) {
                return result;
            }
        }
        return 0;
    }

}
